<template>
	<view class="alert-wrap">
		<u-sticky bgColor="#FFF" customStyle="border-bottom:1px solid #eee;">
			<u-tabs :list="tabList" :scrollable="false" lineWidth="80" lineHeight="2" :duration="100"
				@change="handleTabsClick">
			</u-tabs>
		</u-sticky>
		<view class="content" v-if="tabId == 1">
			<view class="alert-item" v-for="(item, index) in datas" :key="index">
				<view class="middle">
					<u--text lineHeight="22" :text="`站点：${item.groupName}`"></u--text>
					<u--text type="info" :text="`运维人员：${item.maintenanceUser}`"></u--text>
					<u--text type="info" :text="`运维时间：${item.createTime}`"></u--text>
				</view>
				<view class="right">
					<u-button type="primary" icon="edit-pen-fill" shape="circle" size="mini" text="修改"
						@click="handleDispose(item)"></u-button>
				</view>
			</view>
		</view>
		<view class="content" v-if="tabId == 2">
			<view class="alert-item" v-for="(item, index) in datas" :key="index">
				<view class="middle">
					<u--text lineHeight="22" :text="`站点：${item.grouName}`"></u--text>
					<u--text type="info" v-if="item.cod" :text="`COD：${item.cod||''}`"></u--text>
					<u--text type="info" v-if="item.ammoniaNitrogen"  :text="`氨氮：${item.ammoniaNitrogen||''}`"></u--text>
					<u--text type="info" v-if="item.totalNitrogen"  :text="`总氮：${item.totalNitrogen||''}`"></u--text>
					<u--text type="info" v-if="item.totalPhosphorus"  :text="`总磷：${item.totalPhosphorus||''}`"></u--text>
					<u--text type="info" :text="`时间：${item.testTime}`"></u--text>
				</view>
				<view class="right">
					<u-button type="primary" icon="edit-pen-fill" shape="circle" size="mini" text="修改"
						@click="handleDispose(item)"></u-button>
				</view>
			</view>
		</view>
		<view class="alert_btn" style="text-align: right;">
			<!-- 		<u-button type="primary"  shape="circle" :text="tabText"
				@click="handleDispose()"></u-button> -->
			<view class="alert_btnAdd" @click="handleDispose()">
				新增
			</view>
		</view>

		<u-empty mode="list" icon="/static/common/empty.png" :show="total === 0" marginTop="60"></u-empty>
		<u-loadmore :status="loadmoreStatus" v-if="total > queryParams.pageSize" marginTop="20" />
		<u-loading-page :loading="loading" bg-color="#eef3f7" loadingText="zyhjxy.cn"></u-loading-page>
	</view>
</template>

<script>
	import {
		listMaintenance,
		listWaterQuality
	} from '@/apis/modules/maintenance.js';
	export default {
		data() {
			return {
				tabList: [{
					id: 1,
					name: '运维信息',
				}, {
					id: 2,
					name: '水质监测',
				}],
				queryParams: {
					pageNum: 1,
					pageSize: 10,
				},
				loading: true,
				datas: [], // log列表数据
				total: 0, // 总条数
				loadmoreStatus: 'loadmore',
				tmpIds: [], //模板ids
				tabId: 1,
				tabText: "新增运维信息"
			};
		},
		onShow() {
			this.getDatas();
		},
		onLoad(val) {
			if (val.type) {
				this.tabId = val
			} else {
				this.tabId = 1
			}
			this.getDatas();
		},
		created() {
			this.getDatas();
		},
		methods: {
			// 获取列表数据
			getDatas() {
				this.loading = true;
				if (this.tabId == 2) {
					listWaterQuality(this.queryParams).then(res => {
						if (this.queryParams.pageNum == 1) {
							this.datas = res.rows;
						} else {
							this.datas = this.datas.concat(res.rows);
						}
						this.total = res.total;
						this.loading = false;
						uni.stopPullDownRefresh();
					});
				} else {
					listMaintenance(this.queryParams).then(res => {
						if (this.queryParams.pageNum == 1) {
							this.datas = res.rows;
						} else {
							this.datas = this.datas.concat(res.rows);
						}
						this.total = res.total;
						this.loading = false;
						uni.stopPullDownRefresh();
					});
				}

			},
			// 上拉加载
			onReachBottom() {
				this.loadmoreStatus = 'loading';
				this.queryParams.pageNum = this.queryParams.pageNum + 1;
				if ((this.queryParams.pageNum - 1) * this.queryParams.pageSize > this.total) {
					this.loadmoreStatus = 'nomore';
				} else {
					this.getDatas();
					this.loadmoreStatus = 'loadmore';
				}
			},
			// 下拉刷新
			onPullDownRefresh() {
				this.datas = [];
				this.queryParams.pageNum = 1;
				this.getDatas();
			},
			// 处理
			handleDispose(item) {
				if (this.tabId == 1) {
					if (item) {
						uni.navigateTo({
							url: `/pages/maintenance/maintenanceAdd?id=${item.maintenanceId}`
						})
					} else {
						uni.navigateTo({
							url: `/pages/maintenance/maintenanceAdd`
						})
					}
				}

				if (this.tabId == 2) {
					if (item) {
						uni.navigateTo({
							url: `/pages/maintenance/waterQualityAdd?id=${item.waterQualityId}`
						})
					} else {
						uni.navigateTo({
							url: `/pages/maintenance/waterQualityAdd`
						})
					}
				}


			},
			handleTabsClick(e) {
				this.tabId = e.id
				if (this.tabId == 1) {
					this.tabText = '新增运维信息'
				}
				if (this.tabId == 2) {
					this.tabText = '新增水质监测'
				}
				this.datas=[]
				this.getDatas();
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #eef3f7;
	}

	.alert-wrap {
		padding-bottom: 130px;

		.content {
			.alert-item {
				display: flex;
				justify-content: center;
				align-items: center;
				box-shadow: 0 1px 0px 0 rgba(0, 0, 0, 0.1);
				border-radius: 5px;
				margin: 10px;
				padding: 10px;
				background-color: #ffffff;

				.left {
					margin-right: 10px;
				}

				.middle {
					flex: 1;
				}

				.right {
					margin-left: 10px;
				}
			}
		}
	}

	.alert_btn {
		// background-color: blue;
		width: 100%;
		position: fixed;
		bottom: 120rpx;
		display: flex;
		justify-content: end;

		.alert_btnAdd {
			margin-right: 40rpx;
			width: 80rpx;
			height: 80rpx;
			font-size: 30rpx;
			background-color: #3c9cff;
			color: #fff;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
		}

	}
</style>